<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>统计数组数据出现次数</title>
</head>
<body>
    <script>
        var arr = [1,2,3,1,1,1,2,2,3,3,4];

        /* 
            判断对象中是否存在该属性

                * obj[attr]：若不存在attr属性，则obj[attr]值为undefined，转化为布尔值是false

                * attr in obj -> in运算符

        */

        var res = arr.reduce(function(pre,cur){
            if(pre[cur]){
                pre[cur] += 1;
            }else{
                pre[cur] = 1;
            }
            return pre
        },{});

        for(var attr in res){
            console.log(attr + '出现次数：',res[attr]);
        }
    </script>
</body>
</html>